package net.inxweb.bluemeerkat.domain.infrastructure.persistence.hibernate;

import java.util.List;

import javax.annotation.Resource;

import net.inxweb.bluemeerkat.domain.model.glossary.GlossaryType;
import net.inxweb.bluemeerkat.domain.repository.GlossaryTypeRepository;

import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

@Repository("glossaryTypeRepositoryHibernate")
public class GlossaryTypeRepositoryHibernate implements GlossaryTypeRepository {
	@Resource(name = "sessionFactory")
	private SessionFactory sessionFactory; 

	public Long add(GlossaryType glossaryType) {
		return (Long)sessionFactory.getCurrentSession().save(glossaryType);
	} 

	public void modify(GlossaryType glossaryType) {
		sessionFactory.getCurrentSession().update(glossaryType); 
	}

	public void remove(Long id) {
		GlossaryType glossary = (GlossaryType)sessionFactory.getCurrentSession().get(GlossaryType.class, id);
		this.remove(glossary);
	}

	public void remove(GlossaryType glossaryType) {
		sessionFactory.getCurrentSession().delete(glossaryType); 
	} 


	public GlossaryType find(Long id) {
		return (GlossaryType)sessionFactory.getCurrentSession().get(GlossaryType.class, id);
	}

	@SuppressWarnings("unchecked")
	public List<GlossaryType> findAll() {
		return (List<GlossaryType>)sessionFactory.getCurrentSession().createQuery("from net.inxweb.bluemeerkat.domain.model.glossary.GlossaryType").list();
	} 

}
